﻿var KXTX = {};

KXTX.stringify4MVC=function(obj) {
    var url = "";
    var properties = KXTX.GetAllPropertiesExcludeFunction(obj);
    for (var p in properties) {
        var pName = properties[p];
        var pValue = obj[pName];

        if (pValue instanceof Array) {
            url += KXTX.stringifySimpleArray(pName, pValue);
        }
        else {
            url += KXTX.stringifyNotArray(pName, pValue);
        }
    }
    return url;
}

KXTX.stringifySimpleArray=function(key, simpleArray) {
    var url = "";

    for (var i = 0; i < simpleArray.length; i++) {
        url += "&" + _.escape(key) + "=" + _.escape(simpleArray[i]);
    }

    return url;
}
KXTX.stringifyNotArray=function(key, value) {
    var url = "";

    url += "&" + _.escape(key) + "=" + _.escape(value);

    return url;
}

KXTX.GetAllPropertiesExcludeFunction=function(obj) {
    var properties = new Array();
    for (var p in obj) {
        if (typeof (obj[p]) == "function") {
            //obj[p]();
        }
        else {
            properties.push(p);
        }
    }
    return properties;
}


